package com.ebt.m.wiki.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.data.entity.CompanyInfo;

import java.util.List;

/**
 * Created by Damon.Han on 2016/8/6 0006.
 * Corps list adapter
 */
public class CorpsAdapter extends EbtBaseAdapter<CompanyInfo> {
    private Integer cardCompanyId;

    public CorpsAdapter(Context context, List<CompanyInfo> list, Integer cardCompanyId) {
        super(context, list);
        this.cardCompanyId = cardCompanyId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        final CompanyInfo obj = list.get(position);
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.wiki_item_company, null);
            viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.title);
            viewHolder.iv_card_corp = (ImageView) convertView.findViewById(R.id.iv_card_corp);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvTitle.setText(obj.Name);
        if (cardCompanyId != null && cardCompanyId > 0 && position == 0 && obj.Id == cardCompanyId) {
            viewHolder.iv_card_corp.setVisibility(View.VISIBLE);
            viewHolder.iv_card_corp.setImageResource(R.drawable.icon_card_corp);
        } else {
            if (obj.Weight < 10000) {
                viewHolder.iv_card_corp.setVisibility(View.VISIBLE);
                viewHolder.iv_card_corp.setImageResource(R.drawable.icon_primary_corp);
            } else {
                viewHolder.iv_card_corp.setVisibility(View.INVISIBLE);
            }
        }
        return convertView;
    }

    class ViewHolder {
        TextView tvTitle;
        ImageView iv_card_corp;
    }
}
